#!/usr/bin/env perl
use strict;
use warnings;

open my $fh, '<', './constants'
    or die "Could not open the ./constants file for reading\n";

open my $out_file, '>', 'Constants.pm'
    or die "Could not open ./Constants.pm for writing\n";

print {$out_file} <<EOF;
package SM::Constants;
use strict;
use warnings;
use base Exporter;
our \@EXPORT = qw(
EOF

my %constants;

while (my $line = <$fh>) {
    my ($name, $value) = split /\s+/, $line;
    $constants{$name} = $value;
    print {$out_file} "    $name\n";
}

print {$out_file} ");\n\n";
print {$out_file} "use constant {\n";

foreach my $key (keys %constants) {
    my $value = $constants{$key};
    print {$out_file} "    $key => $value,\n";
}

print {$out_file}  "};\n1;";

print "Constants.pm successfully generated from the ./constants file\n";
